from django.db import models
from django.contrib.auth.models import AbstractUser,UserManager as _UserManager

class UserManager(_UserManager):
    """
    自定义user manager修改再使用‘python manage.py createsuperuser’命令时可以提供email
    """
    def create_superuser(self, username, password, email=None, **extra_fields):
        return super().create_user(username=username, password=password, email=email, **extra_fields)

class User(AbstractUser):
    """
    自定义的user模型，添加mobile，email_active字段
    """
    mobile = models.CharField('手机号',max_length=11,unique=True,
                              help_text='手机号',error_messages={'unique':'此手机号已注册'})
    email_active = models.BooleanField('邮箱状态',default=False)
    class Meta:
        db_table = 'tb_user'   # 指定数据库表名
        verbose_name = '用户'   # 在admin站点中的显示名称
        verbose_name_plural = verbose_name  # 复数

    def __str__(self):
        return self.username

    # A list of the field names that will be prompted for
    # when create a user via createsuperuser management command.
    REQUIRED_FIELDS = ['mobile']
    # specify manager
    objects = UserManager()
